package com.flyco.modules.job.order;

import com.flyco.modules.pms.service.IPmsProductService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import groovy.util.logging.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ProductJob {

    private Logger logger = LoggerFactory.getLogger(ProductJob.class);

    @Autowired
    private IPmsProductService productService;

    /**
     * 更新产品的箱规
     */
    //@XxlJob("batchSetProductSkuSpec")
    public ReturnT<String> batchSetProductSkuSpec(String param) throws Exception {

        logger.info("batchSetProductSkuSpec 开始运行");
        try {
            productService.updateProductSpec();
        } catch (Exception e) {
            logger.error("batchSetProductSkuSpec 任务异常："+e.getMessage());
            return ReturnT.FAIL;
        }
        logger.info("batchSetProductSkuSpec 运行结束");
        return ReturnT.SUCCESS;
    }

    /**
     * 当stm_jd_product_base有新的产品时，插入到pms_product，
     * 用户只需要在编辑时补充信息即可。新插入的产品属于下架状态
     */
    //@XxlJob("autoInsertProductByJdProductBase")
    public ReturnT<String> autoInsertProductByJdProductBase(String param) throws Exception {

        logger.info("autoInsertProductByJdProductBase 开始运行");
        try {
            productService.autoInsertProduct();
        } catch (Exception e) {
            logger.error("autoInsertProductByJdProductBase 任务异常："+e.getMessage());
            return ReturnT.FAIL;
        }
        logger.info("autoInsertProductByJdProductBase 运行结束");
        return ReturnT.SUCCESS;
    }

    /**
     *  product_sn!=sku_code 时，更新product_sn
     */
    //@XxlJob("autoUpdateProductSn")
    public ReturnT<String> autoUpdateProductSn(String param) throws Exception {

        logger.info("autoUpdateProductSn 开始运行");
        try {
            productService.autoUpdateProductSn();
        } catch (Exception e) {
            logger.error("autoUpdateProductSn 任务异常："+e.getMessage());
            return ReturnT.FAIL;
        }
        logger.info("autoUpdateProductSn 运行结束");
        return ReturnT.SUCCESS;
    }


    /**
     *  product_sn!=sku_code 时，更新product_sn
     */
    //@XxlJob("autoUpdateProductFromBase")
    public ReturnT<String> autoUpdateProductFromBase(String param) throws Exception {

        logger.info("autoUpdateProductFromBase 开始运行");
        try {
            productService.autoUpdateProductFromBase();
        } catch (Exception e) {
            logger.error("autoUpdateProductFromBase 任务异常："+e.getMessage());
            return ReturnT.FAIL;
        }
        logger.info("autoUpdateProductFromBase 运行结束");
        return ReturnT.SUCCESS;
    }


}
